package com.info.pello;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.regex.Pattern;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.tomcat.util.file.Matcher;

/**
 * Servlet implementation class SignIn
 */
@WebServlet("/SignIn")
public class SignIn extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SignIn() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @throws IOException 
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.getServletContext().
		getRequestDispatcher("/login.jsp").
		forward(request, response);	
	}

	/**
	 * @throws IOException 
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		// TODO Auto-generated method stub
		HttpSession session = request.getSession();
		PrintWriter output = response.getWriter();
		String Login= request.getParameter("name");
		String Password= request.getParameter("password");
		if ((Login.equals("falken")) && (Password.equals("josua"))){
			session.setAttribute("login",Login);
			this.getServletContext().
			getRequestDispatcher("/Private").
			forward(request, response);
			System.out.println("Login correct"); 
		} else {
			request.setAttribute("error", "Login Incorrect");
			this.getServletContext().
			getRequestDispatcher("/login.jsp").
			forward(request, response);	
			System.out.println("Login incorrect");
			}
	}

}
